// 云函数入口文件
const cloud = require('wx-server-sdk')

// 初始化 cloud
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const item = event.item;
  const res = await db.collection('md5_index').doc(item._id).remove();
  if(res.stats.removed == 1){
    await cloud.deleteFile({
      fileList: [item.imgUrl],
    })
    return {code:200, msg:'删除成功', res};
  }else{
    return {code:400, msg:'删除失败', res};
  }
}